<?php


namespace App\Http\Controllers\Common;


use App\Http\Controllers\Controller;
use App\Http\Searchs\Common\Select\HsCodeSearch;
use App\Repositories\Country;
use App\Repositories\Currency;
use App\Repositories\Customer;
use App\Repositories\Dictionary;
use App\Repositories\HsCode;
use App\Repositories\Packing;
use App\Repositories\Port;
use App\Repositories\Transport;
use App\Repositories\Unit;

class SelectController extends Controller
{
    public function unit(Unit $unit)
    {
        return $this->response(
            $unit->get(['code', 'name'])
        );
    }

    /**
     * @param Customer $customer
     * @return \Illuminate\Http\JsonResponse
     * @author luffyzhao@vip.126.com
     */
    public function customer(Customer $customer)
    {
        return $this->response(
            $customer->get(['id as code', 'name'])
        );
    }

    /**
     * @param Country $country
     * @return \Illuminate\Http\JsonResponse
     * @author luffyzhao@vip.126.com
     */
    public function country(Country $country)
    {
        return $this->response(
            $country->get(['code', 'name'])
        );
    }

    /**
     * @param Currency $currency
     * @return \Illuminate\Http\JsonResponse
     * @author luffyzhao@vip.126.com
     */
    public function currency(Currency $currency)
    {
        return $this->response(
            $currency->get(['code', 'name'])
        );
    }

    /**
     * @param Transport $transport
     * @return \Illuminate\Http\JsonResponse
     * @author luffyzhao@vip.126.com
     */
    public function transport(Transport $transport)
    {
        return $this->response(
            $transport->get(['code', 'name'])
        );
    }

    /**
     * @param Packing $packing
     * @return \Illuminate\Http\JsonResponse
     * @author luffyzhao@vip.126.com
     */
    public function packing(Packing $packing)
    {
        return $this->response(
            $packing->get(['code', 'name'])
        );
    }

    /**
     * @param Port $port
     * @return \Illuminate\Http\JsonResponse
     * @author luffyzhao@vip.126.com
     */
    public function port(Port $port)
    {
        return $this->response(
            $port->get(['code', 'name'])
        );
    }

    /**
     * @param HsCode $code
     * @param HsCodeSearch $search
     * @return \Illuminate\Http\JsonResponse
     * @author luffyzhao@vip.126.com
     */
    public function hs_code(HsCode $code, HsCodeSearch $search)
    {
        return $this->response(
            $code->search($search->toArray(), ['code', 'name', 'element', 'unit1', 'unit2'])
        );
    }

    /**
     * @param Dictionary $dictionary
     * @param $code
     * @return \Illuminate\Http\JsonResponse
     * @author luffyzhao@vip.126.com
     */
    public function dictionaries(Dictionary $dictionary, $code){
        return $this->response(
            $dictionary->search($code)
        );
    }
}
